// https://leetcode.cn/problems/keyboard-row/
// Created by ade on 2022/8/8.
//
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution {
public:
    vector <string> findWords(vector <string> &words) {
        unordered_map<char, int> um = {};
        for (auto i : "qwertyuiop") {
            um[i] = 1;
        }
        for (auto i : "asdfghjkl") {
            um[i] = 2;
        }
        for (auto i : "zxcvbnm") {
            um[i] = 3;
        }
        vector <string> res = {};
        for (auto word : words) {
            if (word.size() == 1) {
                res.push_back(word);
                continue;
            }
            int start = um[tolower(word[0])];
            int flag = 1;
            for (int i = 1; i < word.size(); i++) {
                if (um[tolower(word[i])] != start) {
                    flag = 0;
                    break;
                }
            }
            if (flag) {
                res.push_back(word);
            }
        }
        return res;
    }
};

int main() {
    vector <string> nums1 = {"Hello", "Alaska", "Dad", "Peace"};
    Solution so;
    auto a = so.findWords(nums1);
    for (auto i : a) {
        cout << i << ",";
    }
    cout << endl;
    return 0;
}